<?php

// +----------------------------------------------------------------------
// | H1CMS © OpenSource CMS
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2016 http://www.h1cms.com All rights reserved.
// | Copyright (c) 2014-2016 嘉兴领格信息技术有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Allen <allen@lg4.cn>
// +----------------------------------------------------------------------

require __DIR__ . '/../autoload.php';

use h1cms\H1;
use Lg\Options;
use Lg\View\View;
use Lg\Http\Input;
use Lg\Support\Redirect;
use h1cms\model\Language;

function generalAction() {
    $option_names = ['system', 'site', 'mail', 'image'];
    if (Input::isMethod('post')) {
        //维护模式
        maintenance(array_get(Input::post('site', []), 'maintenance',0));
        //更新属性参数
        system_update_options($option_names);
        //删除缓存
        Options::clear($option_names);
        add_flash('success', '系统设置保存成功!');
        return Redirect::to('/system/setting.php?action=general');
    }
    //获取所有语言
    $languages = Language::findAll(['status'=>1]);
    $options = system_get_options($option_names);
    H1::$app->screen->addBreadcrumb(__('常规设置'), '', '', true);
    return View::make('general', [
                'options' => $options,
                'languages' => $languages
    ]);
}
